package com.qdlc.p2p.biz.service.lottery.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.service.lottery.LotteryService;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dao.LotteryDao;
import com.qdlc.p2p.dal.dto.Lottery;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.LotteryModel;

/**
 * 抽奖服务
 */
@Service("lotteryService")
public class LotteryServiceImpl implements LotteryService {

    @Resource
    private LotteryDao lotteryDao;

    public Object process(User user, int category){
        return null;
    }

    /**
     * 保存一条抽奖配置
     * @param model
     * @return
     */
    @Override
    public Lottery save(LotteryModel model) {
        Lottery lottery = LotteryModel.prototype(model);
        lottery.setAddTime(DateUtil.getNow());
        return lotteryDao.save(lottery);
    }

    /**
     * 更新一条抽奖配置
     * @param lottery
     * @return
     */
    @Override
    public Lottery update(Lottery lottery) {
        return lotteryDao.update(lottery);
    }

    /**
     * 查找所有的抽奖配置
     * @return
     */
    @Override
    public PageDataList<Lottery> getAllLottery(LotteryModel model) {
        return lotteryDao.getAllLottery(model);
    }

    @Override
    public Lottery findById(long id) {
        return lotteryDao.find(id);
    }

    @Override
    public double getTotalRate(int category) {
        return lotteryDao.getTotalRate(category);
    }

    @Override
    public List<Lottery> getLotteryByCategory(int category) {
        return lotteryDao.getLotteryByCategory(category);
    }

}
